package com.seawaterbt.ssm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seawaterbt.ssm.config.DataSource;
import com.seawaterbt.ssm.config.DataSourceEnum;
import com.seawaterbt.ssm.entity.CzBasCrew;
import com.seawaterbt.ssm.entity.CzBasHeatstation;
import com.seawaterbt.ssm.entity.ShengBasHeatstation;
import com.seawaterbt.ssm.mapper.ShengBasHeatstationMapper;
import com.seawaterbt.ssm.service.CzBasHeatstationService;
import com.seawaterbt.ssm.service.ShengBasHeatstationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service

public class ShengBasHeatstationServiceImpl extends ServiceImpl<ShengBasHeatstationMapper, ShengBasHeatstation> implements ShengBasHeatstationService {
    @Autowired
    CzBasHeatstationService czBasHeatstationService;
    @DataSource(DataSourceEnum.DB3)
    @Override
    public boolean save(ShengBasHeatstation entity) {
        return super.save(entity);
    }
    @DataSource(DataSourceEnum.DB3)
    @Override
    public boolean saveOrUpdate(ShengBasHeatstation entity) {
        return super.saveOrUpdate(entity);
    }

    @Override
    public void toSend() {
        QueryWrapper<CzBasHeatstation> queryWrapper = new QueryWrapper<>();
        queryWrapper.likeRight("code", 130981011).or().likeRight("code", 130903007);
        List<CzBasHeatstation> czlist = czBasHeatstationService.list(queryWrapper);
        if (czlist != null) {
            for (CzBasHeatstation czBasHeatstation : czlist) {
                ShengBasHeatstation shengBasHeatstation = new ShengBasHeatstation();
                shengBasHeatstation.setADDRESS(czBasHeatstation.getAddress());
                shengBasHeatstation.setAREAPUBLIC(Double.parseDouble(czBasHeatstation.getAreaPublic() == null ? "0" : czBasHeatstation.getAreaPublic()));
                shengBasHeatstation.setAREARESIDENT(Double.parseDouble(czBasHeatstation.getAreaResident() == null ? "0" : czBasHeatstation.getAreaResident()));
                shengBasHeatstation.setAREARSELF(Double.parseDouble(czBasHeatstation.getAreaRself() == null ? "0" : czBasHeatstation.getAreaRself()));
                if (!StringUtils.isEmpty(czBasHeatstation.getCodeProvince())) {
                    shengBasHeatstation.setHEATCOMPANYID(czBasHeatstation.getCodeProvince().substring(0, 9));
                }
                shengBasHeatstation.setHEATINGAREA(Double.parseDouble(czBasHeatstation.getHeatingArea() == null ? "0" : czBasHeatstation.getHeatingArea()));
                shengBasHeatstation.setHEATSTATIONID(czBasHeatstation.getCodeProvince());
                shengBasHeatstation.setHEATSTATIONNAME(czBasHeatstation.getHeatstationName());
                shengBasHeatstation.setHOUSEHOLDCOUNT(czBasHeatstation.getHouseHoldCount());
                shengBasHeatstation.setMAPX(Double.parseDouble(czBasHeatstation.getMapx() == null ? "0" : czBasHeatstation.getMapx()));
                shengBasHeatstation.setMAPY(Double.parseDouble(czBasHeatstation.getMapy() == null ? "0" : czBasHeatstation.getMapy()));
                this.save(shengBasHeatstation);

            }
        }
    }
}
